﻿using System.Collections.Concurrent;

namespace Aeon.Emulator.Keyboard
{
    internal static class ConcurrentQueueExtensions
    {
        public static T Dequeue<T>(this ConcurrentQueue<T> queue, T defaultValue)
        {
            T value;
            if(queue.TryDequeue(out value))
                return value;
            else
                return defaultValue;
        }
        public static T Peek<T>(this ConcurrentQueue<T> queue, T defaultValue)
        {
            T value;
            if(queue.TryPeek(out value))
                return value;
            else
                return defaultValue;
        }
        public static void Clear<T>(this ConcurrentQueue<T> queue)
        {
            while(!queue.IsEmpty)
            {
                queue.Dequeue(default(T));
            }
        }
    }
}
